/**
 * 
 */
package spitfire.ksim.view;

import javax.swing.BoundedRangeModel;
import javax.swing.DefaultBoundedRangeModel;

import spitfire.ksim.simulation.KSimulation;

/**
 * @author Adam
 *
 */
	
	
public class KTunersFrame extends KToolFrame{
	private static final long serialVersionUID = 6946757871565583017L;
	public KSimulation simulation;
	

	public KTunersFrame(final KSimulationView simView) {
		super("Tuners", true, true, true, true);
		setDefaultCloseOperation(HIDE_ON_CLOSE);
			
		BoundedRangeModel refreshPeriodModel = new DefaultBoundedRangeModel(10, 1, 0, 300) {
			private static final long serialVersionUID = -4712633757737271955L;

			@Override
			public int getValue() {
				return (int) (simView.getSimulation().getRefreshPeriod());
			}

			@Override
			public void setValue(int n) {
				simView.getSimulation().setRefreshPeriod(n);
				fireStateChanged();
			}
		};
		add(new KTunerPanel("Refresh", "ms", refreshPeriodModel));
		
//		BoundedRangeModel simTimeModel = new DefaultBoundedRangeModel(10, 1, 0, 1000) {
//			private static final long serialVersionUID = -4712633757737271955L;
//
//			@Override
//			public int getValue() {
//				return (int) (simView.getSimulation().getSimTime());
//			}
//
//			@Override
//			public void setValue(int n) {
//				simView.getSimulation().setSimTime(n);
//			}
//		};
//		add(new KTunerPanel("Refresh", "ms", refreshPeriodModel));
		BoundedRangeModel timeTickModel = new DefaultBoundedRangeModel(60, 1, 1, 360) {
			private static final long serialVersionUID = 3423290540969575363L;

			@Override
			public int getValue() {
				return (int) (simView.getSimulation().getTimeTick() / 1000);
			}

			@Override
			public void setValue(int n) {
				simView.getSimulation().setTimeTick(1000L * n);
				fireStateChanged();
			}
		};
		add(new KTunerPanel("Time tick", "s", timeTickModel));
		
	
		//by Danilo
		BoundedRangeModel dynamicTimeWindowModel = new DefaultBoundedRangeModel(1440, 1, 1, 2880) {
			//private static final long serialVersionUID = 3423290540969575363L;

			@Override
			public int getValue() {
				return (int) (simView.getSimulation().getDynamicTimeWindow() /(1000*60));
			}

			@Override
			public void setValue(int n) {
				simView.getSimulation().setDynamicTimeWindow((1000L * 60L) * n);
				fireStateChanged();
			}
		};
		add(new KTunerPanel("Time window", "min", dynamicTimeWindowModel));
		
		
		simulation = simView.getSimulation();
		
		//##
		
		
		pack();
	}

	
	//by Danilo
//	public KSimulation getSimulation(){
//		return simulation;
//	}
	//##

}
